package utils;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

import java.util.ArrayList;

/**
 * Created by Administrator on 2016/8/9.
 */
public class MyStoreDao {
    MyStoreOpenHelpr myStoreOpenHelpr;
    SQLiteDatabase database;
    public MyStoreDao(Context context) {
        myStoreOpenHelpr = new MyStoreOpenHelpr(context);
        database = myStoreOpenHelpr.getWritableDatabase();
    }
    public void insert(String s){
        ArrayList<String> arrayList =  queryAll();
        if(arrayList.size()==0){
            ContentValues values = new ContentValues();
            values.put("Id",s);
            database.insert("myStore",null,values);
        }else{
            if(!arrayList.contains(s)){
                ContentValues values = new ContentValues();
                values.put("Id",s);
                database.insert("myStore",null,values);
            }
        }
    }

    public ArrayList<String> queryAll(){
        String sql = "select * from myStore";
        ArrayList<String> beanArrayList = new ArrayList();
        Cursor cursor = database.rawQuery(sql,null);
        while (cursor.moveToNext()){
            String Id = cursor.getString(cursor.getColumnIndex("Id"));
            beanArrayList.add(Id);
        }
        Log.e("----",beanArrayList.toString());
        return beanArrayList;
    }
    public void delect(String s){
        database.delete("myStore","Id=?",new String[]{s});
    }


}
